<template>
  <!--财务信息 -->
  <div>
    <FormPanel
      ref="FormPanel"
      :list="initForm"
      :cols="2"
      :formType="formType"
      :labelWidth="150"
      :isSubmitBtn="false"
      @formChange="formChangeHandle"
      class="mtop"
    />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import * as types from '@/api/cms-api/origin/originInfo/types';

import vm from './bridge';

export default {
  mixins: [dictionary],
  model: {
    prop: 'pdata',
    event: 'click'
  },
  props: {
    pdata: {
      type: Object,
      default: () => ({})
    },
    formType: {
      type: String,
      required: true
    },
    formOptions: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      initForm: this.initFormFun()
    };
  },
  mounted() {
    //注册经销商类型变化时触发的事件
    vm.$on('changeDealerType', this.changeDealerType);
  },
  methods: {
    //初始化数据
    init() {
      this.initForm.forEach(x => {
        if (this.pdata[x.fieldName]) {
          x.initialValue = this.pdata[x.fieldName];
        }
      });
    },
    //表单验证通过后
    formChangeHandle(val) {
      this.pdata = Object.assign(this.pdata, val);
      //传递数据到父组件里
      this.$emit('click', this.pdata);
      //触发外部的事件，以标志着本表单已经准备完毕
      this.$emit('formchange', this.pdata);
    },
    //开放的提交方法
    saveDialog() {
      this.$refs.FormPanel.SUBMIT_FORM();
    },
    //经销商类型变更时
    changeDealerType(value) {
      //判断是否是dle页面，是则使用dlr专用验证
      let suffix = this.formOptions.formType === types.DEALER_INFO_FORM_STATUS_SUBMISSION_DLR ? 'DLR' : '';
      //根据类型处理验证
      if (types.DEALER_INFO_DEALER_TYPE_4S === value) {
        //4S
        // vm.changeForm(this.initForm, '4S' + suffix, false);
        vm.clearValidate(this.$refs.FormPanel);
      } else if (types.DEALER_INFO_DEALER_TYPE_SINGLE_AFTER_SALE === value) {
        //单一售后
        // vm.changeForm(this.initForm, 'SH' + suffix, false);
        vm.clearValidate(this.$refs.FormPanel);
      } else if (types.DEALER_INFO_DEALER_TYPE_SINGLE_SALE === value) {
        //单一销售
        // vm.changeForm(this.initForm, 'XS' + suffix, false);
        vm.clearValidate(this.$refs.FormPanel);
      } else if (types.DEALER_INFO_DEALER_TYPE_DIRECT_SHOP === value) {
        //SPACE
        // vm.changeForm(this.initForm, 'SPACE' + suffix, false);
        vm.clearValidate(this.$refs.FormPanel);
      } else if (types.DEALER_INFO_DEALER_TYPE_NO_DIRECT_SHOP === value) {
        //RACE
        // vm.changeForm(this.initForm, 'RACE' + suffix, false);
        vm.clearValidate(this.$refs.FormPanel);
      } else if (types.DEALER_INFO_DEALER_TYPE_BIG_CUSTOMER === value) {
        //大客户
        // vm.changeForm(this.initForm, 'DKH' + suffix, false);
        vm.clearValidate(this.$refs.FormPanel);
      }
    },
    //表单数据
    initFormFun() {
      let bt = { required: true, message: '必填', trigger: ['change', 'blur'] };
      let btl = [];
      let yb = { pattern: /^[0-9][0-9]{5}$/, message: '请填写正确的邮编', trigger: 'blur' };

      return [
        {
          type: 'INPUT',
          label: '开户银行名称',
          fieldName: 'bank',
          initialValue: '',
          maxlength: 300,
          rules: bt,
          rules4S: bt, //4S店
          rulesSH: bt, //单一售后
          rulesXS: bt, //单一销售
          rulesSPACE: bt, //SPACE
          rulesRACE: bt, //RACE
          rulesDKH: bt, //大客户

          rules4SDLR: bt, //4S店(dlr)
          rulesSHDLR: bt, //单一售后(dlr)
          rulesXSDLR: bt, //单一销售(dlr)
          rulesSPACEDLR: bt, //SPACE(dlr)
          rulesRACEDLR: bt, //RACE(dlr)
          rulesDKHDLR: bt //大客户(dlr)
        },
        {
          type: 'INPUT',
          label: '开户行行号',
          fieldName: 'bankNum',
          initialValue: '',
          maxlength: 60,
          rules: bt,
          rules4S: bt,
          rulesSH: bt,
          rulesXS: bt,
          rulesSPACE: bt,
          rulesRACE: bt,
          rulesDKH: bt,

          rules4SDLR: bt,
          rulesSHDLR: bt,
          rulesXSDLR: bt,
          rulesSPACEDLR: bt,
          rulesRACEDLR: bt,
          rulesDKHDLR: bt
        },
        {
          type: 'INPUT',
          label: '银行账号',
          fieldName: 'bankAccount',
          initialValue: '',
          maxlength: 60,
          rules: bt,
          rules4S: bt,
          rulesXS: bt,
          rules4S: bt,
          rulesSH: bt,
          rulesXS: bt,
          rulesSPACE: bt,
          rulesRACE: bt,
          rulesDKH: bt,

          rules4SDLR: bt,
          rulesSHDLR: bt,
          rulesXSDLR: bt,
          rulesSPACEDLR: bt,
          rulesRACEDLR: bt,
          rulesDKHDLR: bt
        },
        {
          type: 'INPUT',
          label: '分账账号',
          disabled: true,
          fieldName: 'subAccount',
          initialValue: '',
          maxlength: 60,
          rules: btl,
          rules4S: [],
          rulesXS: [],
          rules4S: [],
          rulesSH: [],
          rulesXS: [],
          rulesSPACE: [],
          rulesRACE: [],
          rulesDKH: [],

          rules4SDLR: btl,
          rulesSHDLR: btl,
          rulesXSDLR: btl,
          rulesSPACEDLR: btl,
          rulesRACEDLR: btl,
          rulesDKHDLR: btl
        },
        {
          type: 'INPUT',
          label: '邮编',
          fieldName: 'zipCode',
          disabled: true,
          initialValue: '',
          maxlength: 6,
          rules: [bt, yb],
          rules4S: [bt,yb],
          rulesSH: [bt,yb],
          rulesXS: [bt,yb],
          rulesSPACE: [bt,yb],
          rulesRACE: [bt,yb],
          rulesDKH: [bt,yb],

          rules4SDLR: [bt,yb],
          rulesSHDLR: [bt,yb],
          rulesXSDLR: [bt,yb],
          rulesSPACEDLR: [bt,yb],
          rulesRACEDLR: [bt,yb],
          rulesDKHDLR: [bt,yb]
        },
        {
          type: 'INPUT',
          label: '开票电话',
          fieldName: 'invoicePhone',
          initialValue: '',
          maxlength: 30,
          rules: bt,
          rules4S: bt,
          rulesSH: bt,
          rulesXS: bt,
          rulesSPACE: bt,
          rulesRACE: bt,
          rulesDKH: bt,

          rules4SDLR: bt,
          rulesSHDLR: bt,
          rulesXSDLR: bt,
          rulesSPACEDLR: bt,
          rulesRACEDLR: bt,
          rulesDKHDLR: bt
        },
        {
          type: 'INPUT',
          label: '财务负责人电话',
          fieldName: 'financePhone',
          initialValue: '',
          disabled: true,
          maxlength: 30,
          rules: btl,
          rules4S: [],
          rulesSH: [],
          rulesXS: [],
          rulesSPACE: [],
          rulesRACE: [],
          rulesDKH: [],

          rules4SDLR: btl,
          rulesSHDLR: btl,
          rulesXSDLR: btl,
          rulesSPACEDLR: btl,
          rulesRACEDLR: btl,
          rulesDKHDLR: btl
        },
        {
          type: 'TEXT_AREA',
          label: '发票邮寄地址',
          rows: 1,
          fieldName: 'billSendAddress',
          initialValue: '',
          maxlength: 300,
          rules: btl,
          rules4S: [],
          disabled: true,
          rulesSH: [],
          rulesXS: [],
          rulesSPACE: [],
          rulesRACE: [],
          rulesDKH: [],

          rules4SDLR: btl,
          rulesSHDLR: btl,
          rulesXSDLR: btl,
          rulesSPACEDLR: btl,
          rulesRACEDLR: btl,
          rulesDKHDLR: btl
        },
        {
          type: 'INPUT',
          label: '发票邮寄收件人',
          fieldName: 'billAddressee',
          initialValue: '',
          maxlength: 100,
          rules: btl,
          rules4S: [],
          disabled: true,
          rulesSH: [],
          rulesXS: [],
          rulesSPACE: [],
          rulesRACE: [],
          rulesDKH: [],

          rules4SDLR: btl,
          rulesSHDLR: btl,
          rulesXSDLR: btl,
          rulesSPACEDLR: btl,
          rulesRACEDLR: btl,
          rulesDKHDLR: btl
        },
        {
          type: 'INPUT',
          label: '发票邮寄收件电话',
          fieldName: 'billReceiveLinkman',
          initialValue: '',
          maxlength: 20,
          rules: btl,
          rules4S: [],
          disabled: true,
          rulesSH: [],
          rulesXS: [],
          rulesSPACE: [],
          rulesRACE: [],
          rulesDKH: [],

          rules4SDLR: btl,
          rulesSHDLR: btl,
          rulesXSDLR: btl,
          rulesSPACEDLR: btl,
          rulesRACEDLR: btl,
          rulesDKHDLR: btl
        },
        {
          type: 'INPUT',
          label: '紧急联系人',
          fieldName: 'emergencyContract',
          initialValue: '',
          maxlength: 100,
          rules: btl,
          rules4S: [],
          rulesSH: [],
          rulesXS: [],
          disabled: true,
          rulesSPACE: [],
          rulesRACE: [],
          rulesDKH: [],

          rules4SDLR: btl,
          rulesSHDLR: btl,
          rulesXSDLR: btl,
          rulesSPACEDLR: btl,
          rulesRACEDLR: btl,
          rulesDKHDLR: btl
        },
        {
          type: 'INPUT',
          label: '紧急联系电话',
          fieldName: 'emergencyContractPhone',
          initialValue: '',
          maxlength: 20,
          rules: btl,
          rules4S: [],
          rulesSH: [],
          rulesXS: [],
          rulesSPACE: [],
          disabled: true,
          rulesRACE: [],
          rulesDKH: [],

          rules4SDLR: btl,
          rulesSHDLR: btl,
          rulesXSDLR: btl,
          rulesSPACEDLR: btl,
          rulesRACEDLR: btl,
          rulesDKHDLR: btl
        },
        {
          type: 'UPLOAD_FILE',
          label: '开户证明附件',
          selfCols: 2,
          fieldName: 'openAccountProveEnclosureList',
          initialValue: [],
          disabled: true,
          upload: {
            actionUrl: '/api/file/oss/upload', //上传的地址
            limit: 99, //上传数量
            min: 1,
            max: 10240, //kb
            fileTypes: ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'pdf', 'rar', 'zip']
          }
        }
      ];
    }
  }
};
</script>
